<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/page.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/easyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/layui/css/layui.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/css/grid.css">
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/layui/layui.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/layui/layui.all.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/form.js"></script>
	<script>
		$(function(){
			$("#grid").treegrid({url: '${pageContext.request.contextPath}/admin/permission/list',
				method: 'get',
				rownumbers: true,
				idField: 'id',
				fit:true,
				treeField: 'name',
				pagination: true,
				pageSize: 10,
				pageList: [10, 50, 100]});
			<shiro:hasPermission name="permission:query">
			$("#btnSearch").click(function(){
				$("#grid").treegrid({queryParams:form2Json("query")});
			});
			</shiro:hasPermission>
			
			$(".lv-btn-group .lv-btn").click(function(){
				var type = $(this).attr("type");
				var addr = $(this).attr("addr");
				<shiro:hasPermission name="permission:query">
				if(type == "refresh"){
					$(".lv-txtSearch").val("");
					$("#grid").treegrid({queryParams:form2Json("query")});
					return;
				}
				</shiro:hasPermission>
				<shiro:hasPermission name="permission:add">
				if(type == "add"){
					layer.open({
						  type: 2,
						  title: $(this).attr("title"),
						  shadeClose: true,
						  shade: 0.8,
						  area: ['330px', '270px'],
						  content: addr,
						  success:function(layero){
							  $("#grid").treegrid({queryParams:form2Json("query")});
						  }
						});
					return;
				}
				</shiro:hasPermission>
				
				
				var row = $("#grid").treegrid("getSelected");
				if(row == null){
					layer.alert("请选择待操作的数据");
					return;
				}
				if(row.parent === undefined){
					layer.alert("顶级菜单不能修改");
					return;
				}
				<shiro:hasPermission name="permission:modify">
				if(type == "modify"){
					layer.open({
					  type: 2,
					  title: $(this).attr("title"),
					  shadeClose: true,
					  shade: 0.8,
					  area: ['330px', '270px'],
					  content: addr + "?id=" + row.id,
					  success:function(layero){
						  $("#grid").treegrid({queryParams:form2Json("query")});
					  }
					});
					return;
				}
				</shiro:hasPermission>
				<shiro:hasPermission name="permission:delete">
				if(type == "delete"){
					$.ajax({
						url:addr + "?id=" + row.id,
						type:"get",
						success:function(data){
							$("#grid").treegrid({queryParams:form2Json("query")});
						}
					});
					return;
				}
				</shiro:hasPermission>
				
			});
		});
	</script>
</head>
<body>
	<div class="lv-option-container">
		<shiro:hasPermission name="permission:query">
		<form id="query">
			<input type="text" class="lv-txtSearch" name="query"/><div class="lv-btnSearch" id="btnSearch">查询</div>
		</form>
		</shiro:hasPermission>
		
		<div class="lv-btn-group">
			<shiro:hasPermission name="permission:refresh">
			<div class="lv-btn" type="refresh">刷新</div>
			</shiro:hasPermission>
			<shiro:hasPermission name="permission:add">
			<div class="lv-btn" type="add" addr="${pageContext.request.contextPath}/admin/permission/add"  title="添加">添加</div>
			</shiro:hasPermission>
			<shiro:hasPermission name="permission:modify">
			<div class="lv-btn" type="modify" addr="${pageContext.request.contextPath}/admin/permission/modify" title="修改">修改</div>
			</shiro:hasPermission>
			<shiro:hasPermission name="permission:delete">
			<div class="lv-btn" type="delete" addr="${pageContext.request.contextPath}/admin/permission/delete"  title="删除">删除</div>
			</shiro:hasPermission>
		</div>
	</div>
	<div class="lv-grid-container">
		<table id="grid">
			<thead>
				<tr>
					<th data-options="field:'name'" width="220">权限名</th>
					<th data-options="field:'alias'" width="220">权限别名</th>
					<th data-options="field:'description'" width="220">描述</th>
					<th data-options="field:'available', formatter:booleanFormat" width="220">是否可用</th>
				</tr>
			</thead>
		</table>
	</div>
</body>
</html>